package Test_319_6;

import java.util.Random;
import java.util.Scanner;

public class StudentClass {

    //属性
    private  Student[] students;
    //学生的个数
    private int len;

    //行为

    /**
     * 打印班级综合成绩
     */

    public  void printClassStudentInfo(){
        if (students !=null && students.length>0){
            //遍历班级学生，并打印学生信息
            for (Student stu: students) {
                //调用方法打印
                stu.printStuScore();
            }
        }
    }


    //构造方法
    public StudentClass(int len ){
        this.len = len;
        //初始化数组，学生的人数
        if (len>0){
            students = new Student[len];

        }
        else {
            students = new Student[5];
        }
        //随机数给该数组存入各系学生的学生对象

    }

    /**
     * 使用随机数初始化数组
     *
     * @param  students 学生数组对象
     */

    private void initStudentArr(Student[] students){
        //随机数工具类Random
        Random random = new Random();
        //使用控制台输入工具类，从控制台输入信息
        Scanner scanner = new Scanner(System.in);
        //初始化学生数组
        for (int i = 0 ;i<students.length;i++){
            //获取系别的随机数
            int type = random.nextInt(3);

            //随机数确定学生系别
            if (type == 0 ){
                //英语系
                //创建英语系的默认值
                English english = new English();
                //手动输入学生信息，使用控制台
                System.out.println("请输入英语系学生的学号：");
                String stuNum = scanner.next();
                english.setStuNum(stuNum);

                System.out.println("请输入英语系学生的姓名：");
                String stuName = scanner.next();
                english.setStuName(stuName);

                System.out.println("请输入英语系学生的性别：");
                String stuSex = scanner.next();
                english.setStuSex(stuSex);

                System.out.println("请输入英语系学生的年龄：");
                int  stuAge = scanner.nextInt();
                english.setStuAge(stuAge);

                System.out.println("请输入英语系学生演讲成绩：");
                Double stuSpeeches = scanner.nextDouble();
                english.setSpeeches(stuSpeeches);

                System.out.println("请输入英语系学生期中成绩：");
                Double Midterms = scanner.nextDouble();
                english.setMidterms(Midterms);

                System.out.println("请输入英语系学生期末成绩：");
                Double Finals = scanner.nextDouble();
                english.setFinals(Finals);
                //初始化数组元素
                students[i] = english;
            }
            else if (type == 1){
                //计算机系
                //创建计算机系的默认值
                Computer computer = new Computer();

                //手动输入学生信息，使用控制台
                System.out.println("请输入计算机系学生的学号：");
                String stuNum = scanner.next();
                computer.setStuNum(stuNum);

                System.out.println("请输入计算机系学生的姓名：");
                String stuName = scanner.next();
                computer.setStuName(stuName);

                System.out.println("请输入计算机系学生的性别：");
                String stuSex = scanner.next();
                computer.setStuSex(stuSex);

                System.out.println("请输入计算机系学生的年龄：");
                int  stuAge = scanner.nextInt();
                computer.setStuAge(stuAge);



                System.out.println("请输入计算机系学生期中成绩：");
                Double Midterms = scanner.nextDouble();
                computer.setMidterms(Midterms);

                System.out.println("请输入计算机系学生期末成绩：");
                Double Finals = scanner.nextDouble();
                computer.setFinals(Finals);
                //初始化数组元素
                students[i] = computer;

                students[i] = computer;
            }
            else {
                //文学系
                //创建文学系的默认值
                Chinese chinese = new Chinese();

                //手动输入学生信息，使用控制台
                System.out.println("请输入文学系学生的学号：");
                String stuNum = scanner.next();
                chinese.setStuNum(stuNum);

                System.out.println("请输入文学系学生的姓名：");
                String stuName = scanner.next();
                chinese.setStuName(stuName);

                System.out.println("请输入文学系学生的性别：");
                String stuSex = scanner.next();
                chinese.setStuSex(stuSex);

                System.out.println("请输入文学系学生的年龄：");
                int  stuAge = scanner.nextInt();
                chinese.setStuAge(stuAge);

                System.out.println("请输入文学系学生演讲成绩：");
                Double stuSpeeches = scanner.nextDouble();
                chinese.setSpeeches(stuSpeeches);


                System.out.println("请输入文学系学生期中成绩：");
                Double Midterms = scanner.nextDouble();
                chinese.setMidterms(Midterms);

                System.out.println("请输入文学系学生期末成绩：");
                Double Finals = scanner.nextDouble();
                chinese.setFinals(Finals);

                //初始化数组元素
                students[i] = chinese;

            }
        }

    }
}
